/**
 * @author Tobias Boehm
 *
 * 29.03.2011
 */
package org.anddev.andengine.extension.tbsengine.gameobject;

import java.util.HashSet;
import java.util.Set;
import java.util.UUID;

import org.anddev.andengine.extension.tbsengine.gameobject.ability.AbsAbility;
import org.anddev.andengine.extension.tbsengine.match.gamestate.AbsPlayerGameState;
import org.anddev.andengine.extension.tbsengine.resource.ResourceAccount;


/**
 * Instances of this class represent units in your game. It uses an
 * owner (usual a PlayerGameState), an {@link UnitType} and a {@link UUID} as
 * identifier.<p>
 * Notice:<br>
 * You must not create units by calling the constructor {@link #Unit(UnitType, AbsPlayerGameState, UUID)}
 * but by calling {@link UnitFactory#createKnownUnit(String, AbsPlayerGameState, UUID)}
 * or {@link UnitFactory#createNewUnit(String, AbsPlayerGameState)}.
 * 
 * @author Tobias Boehm
 *
 * @param <PlayerGameStateClass> - Your implementation of {@link AbsPlayerGameState}
 */
public class Unit<PlayerGameStateClass extends AbsPlayerGameState> extends GameObject<UnitType> {
	
	private Set<ResourceAccount> mResourceAccounts;
	private final HashSet<IUnitUsedAbilityListener> mUnitUsedAbilityListener;
	private final UnitType mUnitType;
	private PlayerGameStateClass mOwner;
	
	
	public Unit(final UnitType pUnitType, final PlayerGameStateClass pOwner, final UUID pUnitID){
		super(pUnitID, pUnitType);
						
		this.mUnitType = pUnitType;
		
		this.mOwner = pOwner;
		
		this.mUnitUsedAbilityListener = new HashSet<Unit.IUnitUsedAbilityListener>();
	}
		
	public interface IUnitUsedAbilityListener {
		
		public void unitUsedAbility(final Unit pUnit, final AbsAbility pUsedAbility);
	};
	
	public boolean registerUnitUsedAbilityListener(final IUnitUsedAbilityListener pUnitUsedAbilityListener){
		
		return this.mUnitUsedAbilityListener.add(pUnitUsedAbilityListener);
	}
	
	public boolean unregisterUnitUsedAbilityListener(final IUnitUsedAbilityListener pUnitUsedAbilityListener){
		
		return this.mUnitUsedAbilityListener.remove(pUnitUsedAbilityListener);
	}
}
